﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL.ProductBLL;

namespace MDMUI.ProductForms
{
    public partial class ProductForm : Form
    {
        private GetProduct getProduct = new GetProduct();
        public ProductForm()
        {
            InitializeComponent();
            InitializeDataGridView();
            LoadDataIntoDataGridView();
        }
        // 初始化 DataGridView 表头
        private void InitializeDataGridView()
        {
            dataGridView1.Columns.Add("ProductId", "产品id");
            dataGridView1.Columns.Add("EntryAndExitStatus", "工艺流程Id");
            dataGridView1.Columns.Add("EntryAndExitStatus", "工站Id");
            dataGridView1.Columns.Add("EntryAndExitStatus", "进出站状态");
            dataGridView1.Columns.Add("ProductDescription", "产品描述");
            dataGridView1.Columns.Add("ProductType", "产品类型");
            dataGridView1.Columns.Add("Unit", "产品单位");
            dataGridView1.Columns.Add("PackagingForm", "包装形式");

            // 设置列宽
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }

        // 加载数据到 DataGridView
        private void LoadDataIntoDataGridView()
        {
            var products = getProduct.GetProducts(); // 调用BLL方法获取数据

            // 清空 DataGridView
            dataGridView1.Rows.Clear();

            // 添加数据到 DataGridView
            foreach (var product in products)
            {
                dataGridView1.Rows.Add(
                    product.ProductId,
                    product.FlowId,
                    product.StationId,
                    product.EntryAndExitStatus,
                    product.ProductDescription,
                    product.ProductType,
                    product.Unit,
                    product.PackagingForm
                );
            }
        }

        private void ProductForm_Load(object sender, EventArgs e)
        {
            // 窗体加载时自动加载数据
            LoadDataIntoDataGridView();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            // 刷新按钮点击事件
            LoadDataIntoDataGridView();
        }

    }
}
